# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from movie.models import Comment, Review
from auser.models import User
from django.utils.encoding import python_2_unicode_compatible


class CommentPraise(models.Model):
	comment_id = models.ForeignKey(Comment)
	user_id = models.ForeignKey(User)
	status = models.BooleanField(default=False)
	timestamp = models.DateTimeField(auto_now_add=True)

	class Meta(object):
		db_table = "comment_praise"
		verbose_name = "点赞评论"
		indexes = [
			models.Index(fields=['comment_id']),
		]
		unique_together = (("comment_id", "user_id"),)

	def __str__(self):
		return "用户已点赞" if self.status else "用户未点赞"


class ReviewPraise(models.Model):
	review = models.ForeignKey(Review)
	user = models.ForeignKey(User)
	status = models.BooleanField(default=False)
	timestamp = models.DateTimeField(auto_now_add=True)

	class Meta(object):
		db_table = "review_praise"
		verbose_name = "图解点赞"
		unique_together = (("review", "user"),)

	def __str__(self):
		return "用户已点赞" if self.status else "用户未点赞"


@python_2_unicode_compatible
class ReviewComment(models.Model):
	id = models.AutoField(auto_created=True, primary_key=True, db_index=True)
	review = models.ForeignKey(Review)
	user = models.ForeignKey('auser.User')
	user_username = models.CharField(max_length=20)
	content = models.TextField(max_length=100)
	timestamp = models.DateTimeField(auto_now_add=True)
	parent_comment = models.ForeignKey('ReviewComment', related_name="p_r_comment", null=True, blank=True)

	class Meta(object):
		db_table = "review_comment"
		verbose_name = "图解的评论"
		ordering = ['timestamp']

	def __str__(self):
		return "{username}关于review:{title}的评论:{content}".format(username=self.user_username,
		                                                        title=self.review.title,
		                                                        content=self.content)





